<?php

namespace App\Repositories\Article;

use App\Models\Article\ArticleTag;
use App\Repositories\Repository;


/**
 *
 */
class ArticleTagRepository extends Repository
{


    public function list($pageSize=18)
    {
        return ArticleTag::orderBy("weight","desc")->paginate($pageSize);
    }

    public function show($id)
    {
        return ArticleTag::find($id);
    }

    public function store($data)
    {
        try {
            ArticleTag::create($data);
            return $this->respondSuccess();
        } catch (\Exception $e) {
            dd($e->getMessage());
            return $this->respondError(10108);
        }
    }

    public function save($data)
    {
        $tag = ArticleTag::find($data['id']);
        if($tag){
            try {
                $tag->fill($data)->save();
                return $this->respondSuccess();
            } catch (\Exception $e) {
                return $this->respondError(10106);
            }
        }
        return $this->respondError(10106);
    }

    public function del($id)
    {
        try {
            ArticleTag::where("id", "=", $id)->delete();
            return $this->respondSuccess();
        } catch (\Exception $e) {
            return $this->respondError(10107);
        }
    }



    /*
     * ==========================================================================================
     *                                    私有方法
     * ==========================================================================================
    */

}

